package com.tinyengine.it.service.db.impl;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tinyengine.it.common.base.PageQueryVo;
import com.tinyengine.it.mapper.SysTermCacheMapper;
import com.tinyengine.it.model.entity.SysTermCache;
import com.tinyengine.it.model.vo.SysTermCacheVo;
import com.tinyengine.it.service.db.SysTermCacheService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【i_sys_term_cache(系统名词、术语缓存表)】的数据库操作Service实现
 * @createDate 2025-04-25 09:40:58
 */
@Service
public class SysTermCacheServiceImpl extends ServiceImpl<SysTermCacheMapper, SysTermCache>
        implements SysTermCacheService {

    @Override
    public IPage<SysTermCache> getPageList(PageQueryVo<SysTermCacheVo> system) {
        SysTermCacheVo data = system.getData();
        return baseMapper.getPageList(system.getPage(), data);
    }

    @Override
    @Async
    public void updateSysTermCacheInfo(List<SysTermCache> sysTermCacheList) {
        try {
            sysTermCacheList.forEach(s -> {
                SysTermCache sysTermCache = baseMapper.selectOne(new LambdaQueryWrapper<SysTermCache>().eq(SysTermCache::getName, s.getName()).last("limit 1"));
                //baseMapper.delete(new LambdaQueryWrapper<SysTermCache>().eq(SysTermCache::getName, s.getName())/*.eq(SysTermCache::getEnName, s.getEnName())*/);
                if (ObjUtil.isNotNull(sysTermCache)) {
                    s.setId(sysTermCache.getId());
                }
                baseMapper.insertOrUpdate(s);
            });
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}




